In a user interface having a plurality of windows some windows can overlap each other. When rendering a primitive such as a line in one of the rectangular windows the line is clipped to a clip region; that is, a visible region in the rectangular window. One method for clipping the line to the visible region is to compute the intersections of the line with the visible region.
A depth sort algorithm also known as the painter's algorithm can be used to determine the correct order of display. The painter's algorithm renders objects such that the order of display is dependent on distance from the viewing point with the furthest away objects being rendered first. The algorithm renders objects similar to a painter who paints the background first and then adds objects to the foreground.
The algorithm requires a double buffered frame buffer, that is, the image is rendered in a first frame buffer and then copied to a second frame buffer memory from which the image is displayed by the display device. Thus, each window is written to the first frame buffer from back to front with overlapping portions of foreground windows overwriting background windows until the first frame buffer only stores visible regions of the overlapped windows.